package com.cambright
{
	public class Enumerator
	{
		private var _vector:Vector.<Object>;
		private var _index:int = -1;
		
		public function Enumerator(enumerable:Object)
		{
			_vector = Vector.<Object>(enumerable);
			capture();
		}
		
		private function _check():void
		{
			if(_vector == null)
				throw ReferenceError("不可用的迭代器。");
		}
		
		public function reset():void
		{
			_check();
			_index = -1;
		}
		
		public function next():Boolean
		{
			_check();
			return ++ _index < _vector.length
		}
		
		public function get current():*
		{
			_check();
			return _vector[_index];
		}
		
		public function dispose():void
		{
			release();
			_vector = null;
		}
		
		public function capture():void
		{
			reset();
			_vector.fixed = true;
		}
		
		public function release():void
		{
			reset();
			_vector.fixed = false;
		}
	}
}